import 'package:get/get.dart';
import 'package:azring/core/models/relax_info.dart';

/// 助眠状态管理
class SleepAidState {
  /// 是否正在练习
  RxBool isActive = false.obs;
  
  /// 是否暂停
  RxBool isPaused = false.obs;
  
  /// 当前阶段显示
  RxInt currentPhase = 4.obs;
  
  /// 当前计数显示
  RxInt currentCount = 5.obs;
  
  /// 总阶段数
  RxInt totalPhases = 8.obs;
  
  /// 呼吸指导文字
  RxString breathingInstruction = ''.obs;
  
  /// 剩余时间（秒）
  RxInt remainingTime = 0.obs;
  
  /// 已完成的呼吸循环数
  RxInt completedCycles = 0.obs;
  
  /// 圆圈大小
  RxDouble circleSize = 200.0.obs;
  
  /// 动画持续时间
  RxInt animationDuration = 1000.obs;
  
  /// 是否开启环境音效
  RxBool isAmbientSoundOn = false.obs;
  
  /// 练习开始时间
  DateTime? startTime;
  
  /// 练习总时长（分钟）
  RxInt totalDuration = 5.obs;
  
  
  /// 选择的分钟数
  RxInt selectedMinutes = 5.obs;

  /// 减压助眠场景列表
  RxList<RelaxInfo> relaxScenes = <RelaxInfo>[].obs;

  /// 当前选中的场景
  Rx<RelaxInfo?> selectedScene = Rx<RelaxInfo?>(null);

  /// 频次列表
  RxList<RelaxFrequency> frequencies = <RelaxFrequency>[].obs;

  /// 是否正在加载
  RxBool isLoading = false.obs;

  /// 当前呼吸次数（根据选择的分钟数从频次列表获取）
  RxInt breathingFrequency = 37.obs; // 默认5分钟37次

  /// 呼吸节点列表（秒数对应的呼吸指令）
  RxList<BreathingNode> breathingNodes = <BreathingNode>[].obs;

  /// 当前已经过的秒数
  RxInt elapsedSeconds = 0.obs;

  /// 总秒数
  RxInt totalSeconds = 0.obs;
}

/// 呼吸节点数据模型
class BreathingNode {
  final int seconds;
  final String value;

  BreathingNode({
    required this.seconds,
    required this.value,
  });

  factory BreathingNode.fromJson(Map<String, dynamic> json) {
    return BreathingNode(
      seconds: json['seconds'] as int,
      value: json['value'] as String,
    );
  }
}
